package com.tang;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCUtils {

    private static final Logger log = LoggerFactory.getLogger(JDBCUtils.class);

    public static final String URL = "jdbc:mysql://127.0.0.1:3306/medic";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "root";

    public static void main(String[] args) throws Exception {
        // 1.加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        // 2.获取数据库连接
        Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        // 3.操作数据库
        Statement stmt = conn.createStatement();
        ResultSet resultSet = stmt.executeQuery("SELECT * FROM user");
        // 4.取出数据
        while (resultSet.next()) {
            log.info("测试结果=> 姓名：{}， 密码：{}",
                    resultSet.getString("username"),
                    resultSet.getString("password"));
        }

    }

}
